<?php

session_start();
include_once '../dao/Karyawan.php';
include_once '../dao/KaryawanDAO.php';

$nama = $_POST['txtNama'];
$alamat = $_POST['txtAlamat'];
$telp = $_POST['txtTelp'];
$email = $_POST['txtEmail'];
$captcha = $_POST['captcha'];

if ($captcha == $_SESSION['random_number']) {

    $error = false;

    if (strlen(trim($nama)) < 1) {
        $error = true;
    } else if (strlen(trim($telp)) < 1) {
        $error = true;
    }

    if ($error == false) {
        $karyawan = new Karyawan(0, $nama, $alamat, $telp, $email);
        $dao = new KaryawanDAO();        
        echo $dao->insert($karyawan);        
        unset($_SESSION['random_number']); 
        echo 'true';
    } else {
        echo 'false';
    }
}else{
    echo 'Invalid Captch';
}
?>
